﻿// Decompiled with JetBrains decompiler
// Type: Commom.Util.HarvenSin
// Assembly: MT5Trade, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 8045A2CB-DBD6-41AD-8804-F98CAC1BDC8D
// Assembly location: C:\projects\trade\trade_tool\trade0812\MT5Trade.dll

using System;

#nullable disable
namespace Commom.Util;

public class HarvenSin
{
  private static double EARTH_RADIUS = 6371.0;

  public static double HaverSin(double theta)
  {
    double num = Math.Sin(theta / 2.0);
    return num * num;
  }

  public static double Distance(double lat1, double lon1, double lat2, double lon2)
  {
    lat1 = HarvenSin.ConvertDegreesToRadians(lat1);
    lon1 = HarvenSin.ConvertDegreesToRadians(lon1);
    lat2 = HarvenSin.ConvertDegreesToRadians(lat2);
    lon2 = HarvenSin.ConvertDegreesToRadians(lon2);
    double theta = Math.Abs(lon1 - lon2);
    double d = HarvenSin.HaverSin(Math.Abs(lat1 - lat2)) + Math.Cos(lat1) * Math.Cos(lat2) * HarvenSin.HaverSin(theta);
    return 2.0 * HarvenSin.EARTH_RADIUS * Math.Asin(Math.Sqrt(d));
  }

  public static double ConvertDegreesToRadians(double degrees) => degrees * Math.PI / 180.0;

  public static double ConvertRadiansToDegrees(double radian) => radian * 180.0 / Math.PI;
}
